package com.sxj.PDMS.service.impl;

import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxj.PDMS.model.dto.student.YusRecordRequest;
import com.sxj.PDMS.model.dto.student.YusRecordUploadRequest;
import com.sxj.PDMS.model.entity.StudentUploadData;
import com.sxj.PDMS.model.entity.YusRecordSheet;
import com.sxj.PDMS.model.vo.PagingQueryResponse;
import com.sxj.PDMS.service.YusRecordSheetService;
import com.sxj.PDMS.mapper.YusRecordSheetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
* @author 503c'j
* @description 针对表【yus_record_sheet(青年大学习记录表)】的数据库操作Service实现
* @createDate 2024-06-18 16:46:04
*/
@Service
public class YusRecordSheetServiceImpl extends ServiceImpl<YusRecordSheetMapper, YusRecordSheet>
    implements YusRecordSheetService{

    @Autowired
    private YusRecordSheetMapper yusRecordSheetMapper;

    @Override
    public Boolean yusRecordUpload(YusRecordUploadRequest yusRecordUploadRequest) {

            YusRecordSheet yusRecordSheet = new YusRecordSheet();

            yusRecordSheet.setStudentNumber(yusRecordUploadRequest.getStudentNumber());
            yusRecordSheet.setName(yusRecordUploadRequest.getName());
            yusRecordSheet.setGrade(yusRecordUploadRequest.getGrade());
            yusRecordSheet.setImageUrl(yusRecordUploadRequest.getImageUrl());

            boolean saved = this.save(yusRecordSheet);
            return saved;

    }

    @Override
    public PagingQueryResponse<YusRecordSheet> yusRecordSheetSelect(Integer page, Integer pageSize, YusRecordRequest yusRecordRequest) {
        Integer start = (page - 1) * pageSize;
        String name = yusRecordRequest.getName();
        String studentNumber = yusRecordRequest.getStudentNumber();
        String grade = yusRecordRequest.getGrade();

        List<YusRecordSheet> yusRecordSheetList = yusRecordSheetMapper.selectByNameOrGradeOrStudentNumber(start, pageSize, name,grade,studentNumber);
        Long total = yusRecordSheetMapper.selectTotalByNameOrGradeOrStudentNumber(name,grade,studentNumber);

        PagingQueryResponse<YusRecordSheet> pagingQueryResponse = new PagingQueryResponse<>();
        pagingQueryResponse.setRows(yusRecordSheetList);
        pagingQueryResponse.setTotal(total);

        return pagingQueryResponse;
    }

    @Override
    public PagingQueryResponse<YusRecordSheet> selectAll(Integer page, Integer pageSize) {
        Integer start = (page - 1) * pageSize;
        List<YusRecordSheet> yusRecordSheetList = yusRecordSheetMapper.selectAll(start, pageSize);
        Long total = yusRecordSheetMapper.selectTotal();
        PagingQueryResponse<YusRecordSheet> pagingQueryResponse = new PagingQueryResponse<>();

        pagingQueryResponse.setRows(yusRecordSheetList);

        pagingQueryResponse.setTotal(total);

        return pagingQueryResponse;
    }
}




